from django.contrib import admin

# Register your models here.
from .models import Book, Author, Publisher

class BookAdmin(admin.ModelAdmin):
    list_display = ('title', 'display_authors', 'publisher', 'price', 'stock')
    list_filter = ('publisher', 'publication_date')
    search_fields = ('title', 'isbn')

    def display_authors(self, obj):
        return ", ".join([author.name for author in obj.authors.all()])
    display_authors.short_description = '作者'

admin.site.register(Book, BookAdmin)
admin.site.register(Author)
admin.site.register(Publisher)